﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EQual.MainModule.QualityEvents
{
    public class QualityEventProjectPresenter : EQual.Infrastructure.MVPFramework.Presenters.ListPresenterDefault<Projects.Views.IProjectsGridView, object>
    {
        public QualityEventProjectPresenter()
        {
            this.View = new Projects.Views.ProjectsGridView();

            this.View.ItemAdded += new EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>>(View_ItemAdded);
            this.View.ItemSelected += new EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>>(View_ItemSelected);
        }

        void View_ItemSelected(object sender, Microsoft.Practices.Composite.Events.DataEventArgs<object> e)
        {
 
        }

        void View_ItemAdded(object sender, Microsoft.Practices.Composite.Events.DataEventArgs<object> e)
        {
            DataAccesLayer.ProjectsDataAccesLayer DataLayer = new DataAccesLayer.EQualDataLayerFactory().GetProjectsAccesLayer();

            DataLayer.AddNewProject(e.Value);
            DataLayer.AddNewProjectToQualityEvent(e.Value, ActiveItem);
        }

        public override object ActiveItem
        {
            get
            {
                return base.ActiveItem;
            }
            set
            {
                base.ActiveItem = value;
            }
        }

        public override void Dispaly(object item)
        {
            QualityEvnetProjectPresentationModel ViewModel = new QualityEvnetProjectPresentationModel();
            ViewModel.ActiveItem = item;
            this.View.Model = ViewModel;
        }
    }

    public class QualityEvnetProjectPresentationModel : Projects .Models .ProjectsPresentationModel 
    {
        public QualityEvnetProjectPresentationModel():base ()
        {

        }

        protected override IEnumerable<DataAccesLayer.Project> GetCollection()
        {
            return DataFactory.GetProjectsAccesLayer().GetProjectsForQualityEvent(ActiveItem);
        }
    }
}
